package commands;

import core.Zone;

/**
 * A Command to add a new Card to the game, based on an AbstractCard prototype
 */
public class NewCardCommand extends Command
{
	/**
	 * Creates a generic <code>NewCardCommand</code> with <code>set = name = zone = null</code>.
	 */
	public NewCardCommand() {
		this(null, null, null);
	}

	/**
	 * Creates a NewCardCommand to add a card from the given set to the given zone
	 * @param set the set containing the card (see <code>CardParser</code>)
	 * @param name the name of the card
	 * @param zone the Zone to which the card should be added
	 */
	public NewCardCommand(String set, String name, Zone zone) {
		this.set = set;
		this.name = name;
		this.zone = zone;
	}

	/**
	 * Looks up the AbstractCard prototype in the provided set by the provided name. 
	 * If it is found, initializes a new Card and stores it in the provided Zone.
	 */
	public net.StateUpdate execute() throws CommandException
	{
		if (zone == null)
			throw new CommandException(this, "null zone in NewCardCommand");

		net.StateUpdate stateUpdate = super.execute();
		newCard = new core.Card(new core.CardIdentifier(set, name));
		newCard.setVisibility(zone.getDefaultVisibility());
		stateUpdate.addChange(new net.ChildAddition(zone, "card", newCard));
		return stateUpdate;
	}
		
	public String toString() {
		return "NewCardCommand: set=" + set + " name=" + name + " zone=" + zone;
	}

	public Zone getZone() {
		return zone;
	}

	public void setZone(Zone zone) {
		this.zone = zone;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSet() {
		return set;
	}

	public void setSet(String set) {
		this.set = set;
	}

	public String getMessage() {
		return "new card " + util.Util.prettyPrint(newCard) + " in " + util.Util.prettyPrint(zone);
	}

	private String set, name;
	private Zone zone;
	private core.Card newCard = null;
}